changes code to use reject and unshift methods