add 304 support and refine code