Added dependencies check on setup.py. Fix minor bugs and added more controls on mainfunctions.