split lib and main scripts into separate files