Bug fixes (should go to sleep now, really! there are just too many bugs)