incorporated Ian's changes into my working changes