Finally a version that mostly works