simplified control scheme and cleaned up code