Clean up code, improve commenting, remove manual reset.