Fix stuff and make it more portable.