Fix issue #49

I fixed issue #49, and refactored some code.