Broke out code

For easy updating and modification