I refactored some of the functions and made it cleaner