Added cmake, rearranged code some more