Added unittests and finished basic training procedure.