fix bugs and add cache