Reworked basic architecture, and fixed most bugs