Move declarations to top of scope to improve portability of code