more refactor and code clean up