Renamed and commented things so that the code is more readable and
understandable. Also deleted some obsolete code.