refined main functions, documented too