Fixing misc bugs