added more elegant solution