This code has a bug. Need help fixing it.