Code cleanup / refactoring