Refactored some functions into tools