Bug fix and lots of other stuff