Refactored. There are still two long lines, but I can't really get around those...