changed back function
orginised code and defined data type