Re-factored parse_file and fixed bug with environment