bug fixed; a test added.