Implemented solutin to problem
Need free mechanism for perfect solution though