Improved loops, remove unwanted functions.