Tidy up code and add back support for browsers