more refactoring/improvements