fixed some bugs, but lots left to go!