Main routines implemented. Tested on Win7.