Refactor to be more idomatic javascript, fix chrome detection