Adding intelligence

This is really hard.