Fix some bugs (thanks, cpp-check) and add support for selections

-They're not really useful right now