added share feature, rearranged some code