Move parsing to top-level function