moving method to javascript