code cleanup, simulator fixes