Fixed bug in implementation