(cleanup) added comments and grouped related code blocks