Fixed calls and moved variables declarations to start of functions.