Refactor some code & fix UX