Sets onclicklistners and fixes bugs