Fixed some bugs + etc

Does not run, but did the best I could to work out the kinks.