goobypleaseexception rewritten in scala, algorithm bit improved