updated code, included tests ( test 5, 8 and 9 need to be updated )