code fixing and clean up