Enh: moved core js code in a separate file