other function and cleaned up code