changed several lines to shorten the code