Fix some dialyzer warnings

This is a WIP, not ready to merge yet.