Correcting bug in code