A quite generally formulated multilevel quasi-geostrophic medel with possibilities to include second order terms in the vorticity equation is derived. The model includes friction, topography, latent heat and sensible heat. The treatment of the variable boundary conditions, smoothing and ellipticity control is described.