Added type checking for issue 41, added unit test for it