Removed unused variables, fix some warnings (signed compare etc)