Code cleanup, rename functions