Remove no longer required old code
Pull out some functionality to separate helper functions