added docs and fixed Y.when