Refactor functions and remove deprecated function