Refactor functions and update names