Initial code port, let me know if it complains.