Fixed according to comments and added tests for new cases