Moved bash functions to external file. Refactored some if statements