slightly cleaner implementation of previous commit