Code clean up and minor refactor