Fixes for bugs found while testing