Closes issue #7 and code is also now cleaned up a little.