A version that seems to be working :)