Cache headers & fix potential memory leak