some sorting, bit operations, and tree traversals stuff