Refactor frontend code