fixed intermediate function