Cleaning up gate code.