final version working