removed unused imports and safer call to 'code'