changed function names and refactored some code