Updated to fewer lines of code