Fixed JS finally
Added ImageLoaded plugin to use masonry after the images are loaded. Now the sizes are detected correctly