Add original file
Fix all important warnings

1. remove uses of free variables.
2. update some obsolete functions.