Added duplicate function and cleaned up some code!