Code cleanup - avoid to many nested blocks in function.