figured out how to use halt to simplify code