The construction of result and downMenu would be much more understandable as a template in `tpl/`. It's really hard to follow what's where and which `<div>` is closed by which `</div>` and will be much harder to edit without introducing accidental unclosed elements.