Enhanced Directive Parsing and Code Cleanup