Added snapping code
Further grid implementation.