code cleaned up using SplitBlockIfThen()