Now the function is fast, but less ugly