Code refactor: moved logic from view to classes