added test & fixed bugs