made code more functional