updated code to work