Tidying

Fixed bugs, cleaned up some stuff.