refactoring, added comments on hacky codes