restructured code and removed a console log