added short-circuiting to reduce functions.