clean code big refactor fix some bugs