Breaking code up into functions and remove file extension

Reusable code is good