a rewrite of previous code