fixed a few bugs, tidy up