Return codes consistency plus various cleanups