Closing in on bugs. Feeling more confident about this code