Add sd in error and fix bugs