fixed commenting, rearranged functions