cleaned up parsing into a function without global vars