Fixed a few more bugs...now seems to work