Corrected bug in code