Detabify and tidy up some more of the bugs code