Fixed some bugs that almost killed me...