Define variables on top to prevent weird race conditions