Bug fixes on javascript