Code simplification and better comments