Improved documentation, reformatted code for readability