Refactor some code and improved code for less map reloading