clean some code, optimize