refactored everything neatly and added csv conversion as well as modified validation for pat