refactored some functions