merged version, functional