Refactor, simplify and cleanup.