Fix bugs and make it backward compatible