Cleaned up code slightly, have not fixed bugs yet though