[IM] Tidying up code
[BF] Fixing logic
[IM] Better AJAX handling