Code showing error even though it is correct