cleaned up and updated code