complete solution with many fixes, all basic functions works