Various bug fixes

Fixing more bugs