Code fixes and tests updated