1) refactored setup() function into several smaller functions for better readability and future maintenance, 2) added beginning of --clean and --mkdirs support