Some optimization, cleanup, add toggle. Closes #1