bug fixes with state and a test app