More checks for external libs and restructured whole file