Revised and reformatted code.