Refactor gen patches

Refactored gen-patches.rb

solves #2, #3, #4, #5 and #8