final updated code