More code refactoring/cleanup