Made some modifications and bug fixes.