lot of code refactoring, mainly for readability. Found some weird stuff you would not want to know!