Refactored some functions.