added unpack_results method and refactored code