added Tests and fixed bug