Fixed minor bugs. Tested to work in other environments.