Slightly improved version of previous code. Doesn't compile