refactor js and added version check