worked version with base functions