Fisrt working edition with all tests passed