updated code to final version