Fixed a few bugs and got it working mostly