Finally got the basic function working.