update and cleaning up code