Code cleanup

- remove unneeded variables
- replace ternary operator with array_splice call