update discharge logic & error redirect