Some fixes

Resubmitted PR for some fixes.