Read function done in a way more generic way. Some structural changes should be made