Moved code from icybee/core