Add flood protection (resolves #1), minor cleanups