rebased with most recent code