move common code to helpers
move match issue pattern matching to function
svn: restructure code to be more modular