Move parsing into function