Finished port from PB to JS.