made code more concise and test pass