Updating code

Some optimization and messages in Json format