cleaner version of previous code