Misc bugfixes (horrible commit msg ftw)