added test, bugs fixed