This is code duplication, should be moved in utils to allow reuse