added better selection handling, some other fixes