Style and bug fixes

This takes care of many issues I posted in my feedback issue.