more refactoring and cleaing code