Rework slightly to get rid of deprecated API usage