Added and fixed some functions, reviewing and migrating the old codes