Refactor pre commit hook

Added whitespace protection and simplified some parts