moving int declaration to top of function to avoid upsetting old compilers