Refactor and further clean up.