Updating code to correct data types, and moving declarations outside if statement.
Adding better unit awareness