added a test, fixed a bug