Did some refactoring and optimization for 2D Engine