Removed extra code, checked for invalid moves