Fixed undefined errors so it's compatiable within the browser