fast matrix access added and code cleaning