Added tests and fixed edge case issues including a YUI bug workaround