Moved define constants to global scope
Added missing var declarations