Seems to work, removing some debug code