Simplified code, added some compilation flags.