move some javascript functionality to seperate methods for reusability purpose