Fixes for various bugs found