Added in some of the improvements suggested by @anavarre