Re-organized functions and added parameters.