Refactor and remove document ready