This Fixes #906,#899

Please review and let me know if this is fine.