first working version of parser function