moved mosaic functions to js