Working code with bugs