Revised with comments from fspindle