Merge pull request #6 from mkhl/more_functions

Extract many tiny functions