An a bit more modular approach
Fixed some major bugs