Refactor

Use method to call js instead of forming javascript code