improving matrix helper