Cleaned up and updated core js code