Fix major bugs. FIRST WORKING VERSION!