Major refactor and psr2 fixes