Moved reading to function