Rename functions. Fix bugs