Implement modified version of @fana-m 's previous commit