fixed an off-by-one and division by 0 error, removed some logging