fixed bug and added implementation