More bug fixes, added unit tests