various bug fixes, NPEs and such found during testing