Refactored javascript into 'classes'