remove unecessary ret checks, move declarations to top of function