changed len() to count(), and bugfix