some refactoring
removed extra squares
sync with master