Added entity masks

+ added entity masks
+ some formatting and commenting