second version with all the updated code