object orientated version implemented, test case added