Bugs on functions corrected.