updated code, cleaned up comments