Fixed most bugs. Code needs to be refactored