Direct port from PyTeaser