Changed the code
did some re organisation