Final code for Lab3