fix type conversion errors and got rid of unused variables