reconstruct the code and bug fix
Reconstruct the code for better OS-independent.