performance improvements via cellfun. not really efficient :(