simplified version
removing prints