Add gitignore
Refactor into subroutines