Refactor some complexity in Beanstalk