Improved the code a bit and added code contract. Closes #33

If it crops up again will have more information, at least.