edited version for codereview