Final version, and Test function