added script for self-testing; moved classification part into a function