clean up the code

refactoring structure and code