huge refactor
Fixed an NPE