Subroutine to tidy up the code

Removing non-changed cuts from the main routine and moving it to subroutine setting the correct values