Trying to simplify code