Bug fixes to previous implementation, and an extended unit test