Refactor circle javascript