Major code refactoring, minor UI changes