split code to minimal functions