Moved code to gallery lib