Restructured 'functions.R'