#13 added another subquery and refactoring