make operations more safe and fix tests for functional use case