refactor code in coffee