fixed Nimit's code