Removed some small logical errors