Fixed a few bugs, seems to be working