Refactored all code and wrote functions to handle data