remove duplicate code
Merge pull request #27 from theckman/improve_code

remove duplicate code