move initialization to function and use data attribute