Bug fixes according to unit tests
Fixed issue #4