remove unused vars and outputs.
handling error code