Selection tool tweaks

Also organized some code and functions, but unfortunately I've forgot to create separate commit for it :(