Added DOM ready condition check and moved the script inclusion at the top