refactor code and update frontend