corrected runtime error and organised in an OO structure.