Cleaner implementation.

This is more lines, but I think it's easier to read.