Finally working and tested