The system of single member constituencies with first past the post is the root cause of these problems.
Electoral systems involving multi-member constituencies and proportional representation can eliminate the worst of them, and make it extremely hard to effectively gerrymander so as to cause unfair outcomes.