Bug fixes; #184 #185 #188

Bug fixes; #184 #185 #188 

@raamdev This PR includes everything I submitted in #184 #185 too. I had to do that in order to resolve the final issue reported here in #188. Sorry for any confusion. If you'd like to simplify this a bit, you can simply close the pull requests associated with #184 and #185 and just merge this one. That would do fine.