Got the basic function working