Working code- Revision 1