Some refactoring and tiles redraw bug fixed