Added functions

Separated code into functions and added Twitter functionality.