Refactor and cleanup frontend