refactored handle encounter to work as a code, and be re-used over multiple encounters