added some semicolons. split up parts into individual functions