making use of R.filter to simplify logic also updated test cases