Fix some bugs

Fixes a bunch of bugs and adds some requested features