Updated code, refactored and moved into classes, still a work in progress