Code fix and clean up