Use size_t appropriately, make casts explicit, remove forcing to bool