Shorten code

Attempt to shorten code. Not sure it works yet.