minimally cleaned up code