Apply some clean code principles

Move functionality out of UI