more beautification and refactoring