Improving and relocating some functions and typos