working final version