Improved Clip function

new clip function made, working to generalize it, fix any bugs