renamed libraries, fixed flag and refactored code