Js refactor casts