Refactored functions and added class structure