made code more efficient by cutting functions