use [].slice instead of loop and add tests