Refactor and clean up a little