Fixed error in function