Suggested by ermal, function name changed and redesigned