Optimized code a bit, usinjg linq, converting to var, null exceptions etc..

Take it if you want :)