made code similar to latest snippet