Fixing some testing logic. Cleaning up js a bit