Refactoring, optimizations, UI tweaks