update with more elegant solution