Shortening code with use of methods