updated and cleaned up newest code