updated with changes from commit 406fb2e