Bug fix: same as last time, but smarter!