added test, and bug fixing