Refactor to use jquery plugin architecture