code optimized and json in success