Improvements and bug correction.

Made some improvements I think you'll like.