Backporting to older Erlangs and more error checking.