Comptacted code, still some bugs to fix