final version working!