implemented war function exactly as it was written in the description