More rigourous way of programming. No need to free the memory as at the first fail from this file the programme stops.