Fix function attributes and add tests