Simplify the code in a number of places

Resolve all TODO items as well