extract Snake class; add some unit tests