Code refactoring/improvements