added pre/post conditions to code