repaired slightly bad implementation