Refactor more functions