Adding subroutines
Moved entire creation code into new subroutine