Assertion error

Fix for issue #16 and improved tests