Fix code to work in browser