This still needs a lot of work though. (imported from commit 4472488c399f7c5b96bcf900b1a5e957625cb450)